from api.login import LoginAPI
from api.stnff import StaffAPI
from common.dbutil import DBUtil
from common.assertPackage import common_assert
# 创建测试类
class TestStaffAPI:
    token666 = None
    id666 = None

    def setup_class(self):
        # 清理测试数据
        DBUtil().exe_sql("delete from bs_user where mobile = '13703032102';")

        # 实例化接口类
        self.login_api = LoginAPI()
        self.staff_api = StaffAPI()
        # 前置条件：登录成功
        response = self.login_api.login({"mobile": "13800000002", "password": "123456"})
        # 提取响应结果中的data数据并保存至类的属性中
        TestStaffAPI.token666 = response.json().get("data")
        print(TestStaffAPI.token666)

    # 测试方法（添加员工成功）
    def test01_insert_staff(self):
        insert_data = {
            "username": "jack070901160001",
            "mobile": "13703032102",
            "timeOfEntry": "2020-07-09",
            "formOfEmployment": 1,
            "workNumber": "01160001",
            "departmentName":"销售",
            "departmentId":"1266699057968001024",
            "correctionTime":"2020-07-30T16:00:00.000Z"
        }
        response = self.staff_api.insert_staff(insert_data, TestStaffAPI.token666)
        print(response.json())
        # 断言
        # assert response.status_code == 200
        # assert response.json().get("success") is True
        # assert response.json().get("code") == 10000
        # assert "成功" in response.text
        common_assert(response)
        # 关联：提取id并保存类的属性
        TestStaffAPI.id666 = response.json().get("data").get("id")
        print(TestStaffAPI.id666)
    def test02_select_staff(self):
        response=self.staff_api.select_staff(TestStaffAPI.id666,TestStaffAPI.token666)
        print(response.json())

        common_assert(response)
        # assert response.status_code == 200
        # assert response.json().get("success") is True
        # assert response.json().get("code") == 10000
        # assert "成功" in response.text
    def test03_update_staff(self):
        update_staff = {
            "username":"sjl"
        }
        response = self.staff_api.update_staff(TestStaffAPI.id666,TestStaffAPI.token666,update_staff)
        print(response.json())

        common_assert(response)
        # assert response.status_code == 200
        # assert response.json().get("success") is True
        # assert response.json().get("code") == 10000
        # assert "成功" in response.text
    def test04_del_staff(self):
        response = self.staff_api.del_staff(TestStaffAPI.id666,TestStaffAPI.token666)
        print(response.json())

        common_assert(response)
        # assert response.status_code == 200
        # assert response.json().get("success") is True
        # assert response.json().get("code") == 10000
        # assert "成功" in response.text